from PyQt5 import sip
from PyQt5.QtWidgets import QMessageBox


def exit_game(self):

    if not sip.isdeleted(self.xyf_button) and not sip.isdeleted(self.jbc_button):
        self.xyf_button.pause()
        self.jbc_button.pause()
    exit_dialog = QMessageBox()
    exit_dialog.setWindowTitle("暂停游戏")
    exit_dialog.setText("你确定要退出游戏吗？")
    exit_dialog.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
    exit_dialog.setDefaultButton(QMessageBox.No)
    if exit_dialog.exec_() == QMessageBox.Yes:
        exit_to_main_menu(self)
    else:
        if not sip.isdeleted(self.xyf_button) and not sip.isdeleted(self.xyf_button):
            self.xyf_button.resume()
            self.jbc_button.resume()
    pass


def exit_to_main_menu(self):
    self.ui.stackedWidget.setCurrentIndex(0)
    if not sip.isdeleted(self.jbc_button) and not sip.isdeleted(self.xyf_button):
        self.xyf_button.cleanup()
        self.jbc_button.cleanup()
